package us.mooresr.aircraftscheduling.client.ui;

import us.mooresr.aircraftscheduling.client.AdminGatekeeper;

import com.gwtplatform.mvp.client.Presenter;
import com.gwtplatform.mvp.client.ViewImpl;
import com.gwtplatform.mvp.client.proxy.PlaceManager;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;


public class MainPageView extends ViewImpl implements MainPagePresenter.MyView {

	private final Widget widget;
	private Presenter presenter;
	
	@UiField
	FlowPanel contentPanel;
	
	@UiField(provided=true)
	MainMenu mainMenu;

	public interface Binder extends UiBinder<Widget, MainPageView> {
	}

	@Inject
	public MainPageView(final Binder binder, final PlaceManager placeManager) {
		mainMenu = new MainMenu(placeManager);
		widget = binder.createAndBindUi(this);

		
	}

	@Override
	public Widget asWidget() {
		return widget;
	}
	
	@Override
	public void setInSlot(Object slot, Widget content) {
		if (slot == MainPagePresenter.TYPE_SetMainContent) {
			setMainContent(content);
		} else {
			super.setInSlot(slot, content);
		}
	}

	private void setMainContent(Widget content) {
		contentPanel.clear();

		if (content != null) {
			contentPanel.add(content);
		}
	}

	@Override
	public void revealAdminFunctions(Boolean b) {
		if (b) {
			mainMenu.showAdminFunctions();
		} else {
			mainMenu.hideAdminFunctions();
		}
		
	}

	@Override
	public void setUsername(String currentUserName) {
		mainMenu.setUsername(currentUserName);
		
	}
	

	@Override
	public void setPresenter(MainPagePresenter mainPagePresenter) {
		this.presenter = mainPagePresenter;
		mainMenu.setPresenter(mainPagePresenter);
	}
	
	
}
